package whf.framework.web.query;

import java.util.Collections;
import java.util.Set;

import whf.framework.util.StringUtils;
import whf.framework.util.Utils;

/**
 * @author wanghaifeng
 *
 */
public class BOField extends Field {
	public BOField(String name, String[] values){
		super(name, values);
	}

	@Override
	public String toHQLString() {
		Set<String> items = Utils.newHashSet();
		for(String value: values){
			String[] vals = StringUtils.split(value, ",");
			Collections.addAll(items, vals);
		}
		StringBuilder sb = new StringBuilder("(");
		int count = 0;
		for(String item: items){
			if(sb.length() > 1) sb.append(" or ");
			if(item == null || "0".equals(item)) continue;
			sb.append("t.").append(name).append(".id=").append(item);
			count ++;
		}
		sb.append(")");
		if(count == 0)
			return null;
		else
			return sb.toString();
	}
	
}
